﻿using System;
using Terraria.ModLoader.IO;

namespace Terraria.ModLoader.Default
{
	// Token: 0x02000302 RID: 770
	public class MysteryTileEntity : ModTileEntity
	{
		// Token: 0x06001D58 RID: 7512 RVA: 0x00014C88 File Offset: 0x00012E88
		internal void SetData(TagCompound tag)
		{
			this.modName = tag.GetString("mod");
			this.tileEntityName = tag.GetString("name");
			this.data = tag.GetCompound("data");
		}

		// Token: 0x06001D59 RID: 7513 RVA: 0x00438D64 File Offset: 0x00436F64
		public override bool ValidTile(int i, int j)
		{
			Tile tile = Main.tile[i, j];
			return tile.active() && ((int)tile.type == base.mod.TileType("MysteryTile") || (int)tile.type == base.mod.TileType("PendingMysteryTile"));
		}

		// Token: 0x06001D5A RID: 7514 RVA: 0x00014CBD File Offset: 0x00012EBD
		public override TagCompound Save()
		{
			TagCompound tagCompound = new TagCompound();
			tagCompound["mod"] = this.modName;
			tagCompound["name"] = this.tileEntityName;
			tagCompound["data"] = this.data;
			return tagCompound;
		}

		// Token: 0x06001D5B RID: 7515 RVA: 0x00014CF7 File Offset: 0x00012EF7
		public override void Load(TagCompound tag)
		{
			this.SetData(tag);
		}

		// Token: 0x06001D5C RID: 7516 RVA: 0x00438DBC File Offset: 0x00436FBC
		internal void TryRestore(ref ModTileEntity newEntity)
		{
			Mod mod = ModLoader.GetMod(this.modName);
			ModTileEntity modTileEntity = (mod != null) ? mod.GetTileEntity(this.tileEntityName) : null;
			if (modTileEntity != null)
			{
				newEntity = ModTileEntity.ConstructFromBase(modTileEntity);
				newEntity.type = (byte)modTileEntity.Type;
				newEntity.Position = this.Position;
				newEntity.Load(this.data);
			}
		}

		// Token: 0x040018F0 RID: 6384
		private string modName;

		// Token: 0x040018F1 RID: 6385
		private string tileEntityName;

		// Token: 0x040018F2 RID: 6386
		private TagCompound data;
	}
}
